package com.fqgj.xjd.user.dao.impl;

import com.fqgj.common.base.AbstractBaseMapper;
import com.fqgj.xjd.user.dao.UserThirdPartDao;
import com.fqgj.xjd.user.entity.UserThirdPartEntity;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

/**
 * User: sm
 * Date: 2018-04-12
 * Time: 16:39:21.311
 */

@Repository
public class UserThirdPartDaoImpl extends AbstractBaseMapper<UserThirdPartEntity> implements UserThirdPartDao {

    @Override
    public Integer insertWithCustomId(UserThirdPartEntity userThirdPartEntity) {
        return getSqlSession().selectOne(getStatement("insertWithCustomId"), userThirdPartEntity);
    }

    @Override
    public UserThirdPartEntity selectOneByOpenId(String openId) {
        return getSqlSession().selectOne(getStatement("selectOneByOpenId"), openId);
    }

    @Override
    public UserThirdPartEntity selectOneByUserCode(String userCode) {
        return getSqlSession().selectOne(getStatement("selectOneByUserCode"), userCode);
    }

    /**
     * 根据userCode更新openId
     * @param userCode
     * @param openId
     */
    @Override
    public void updateOpenIdByUserCode(String userCode, String openId) {
        Map<String, String> map = new HashMap<>();
        map.put("userCode", userCode);
        map.put("openId", openId);
        getSqlSession().update(getStatement("updateOpenIdByUserCode"), map);
    }

    /**
     * 根据openId更新userCode
     * @param userCode
     * @param openId
     */
    @Override
    public void updateUserCodeByOpenId(String userCode, String openId) {
        Map<String, String> map = new HashMap<>();
        map.put("userCode", userCode);
        map.put("openId", openId);
        getSqlSession().update(getStatement("updateUserCodeByOpenId"), map);
    }
}